home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / tblt / tblt⁄dlog.c < prev    next >
Encoding:
Text File  |  1986-09-06  |  2.0 KB  |  87 lines  |  [TEXT/MACA]

  1. /*
  2.  * dlog.c - handle dialogs for the game of Tablut
  3.  *
  4.  */
  5.  
  6. #include <memory.h>
  7. #include <quickdraw.h>
  8. #include <window.h>
  9. #include <event.h>
  10. #include <textedit.h>
  11. #include <dialog.h>
  12. #include <control.h>
  13. #include <toolutil.h>
  14. #define watchCursor 4    /* Should be in TOOLUTIL.H but isn't.  */
  15. #include <resource.h>
  16.  
  17. /*
  18.  * saydialog() - show the user the given dialog.
  19.  */
  20. saydialog(dlgid)
  21. short dlgid;    /* Resource ID of the dialog to show */
  22. {
  23.     short itemhit;        
  24.     DialogPtr reportptr;
  25.  
  26.     /*
  27.      * Get the dialog; NIL => use heap storage; -1 => make dlg frontmost.
  28.      * Wait for some item to be selected (OK is the only one),
  29.      * then free up the memory and erase the dialog.
  30.      */
  31.     reportptr = GetNewDialog(dlgid, (char *) 0, (long) -1);
  32.     ModalDialog((ProcPtr) 0, &itemhit);
  33.     DisposDialog(reportptr);
  34. }
  35.  
  36. /*
  37.  * radioswitch() - turn one radio button off & another one on,
  38.  *  returning the item ID of the new "on" button.
  39.  */
  40. int
  41. radioswitch(ptr, oncontrl, offcontrl)
  42. DialogPtr ptr;
  43. int oncontrl, offcontrl;    /* items to turn on and off, respectively */
  44. {
  45.     int itemtype;
  46.     ControlHandle item;
  47.     Rect itembox;
  48.  
  49.     GetDItem(ptr, offcontrl, &itemtype, &item, &itembox);
  50.     SetCtlVal(item, 0);
  51.     GetDItem(ptr, oncontrl, &itemtype, &item, &itembox);
  52.     SetCtlVal(item, 1);
  53.     return(oncontrl);
  54. }
  55.  
  56. /*
  57.  * justdigs() - restrict the contents of an EditText item to just the given
  58.  *  number of digits.  I.E., throw out non-digit characters & characters
  59.  *  beyond the end of the field.
  60.  * The field must be less than 100 characters wide.
  61.  */
  62.  
  63. justdigs(ptr, field, width)
  64. DialogPtr ptr;
  65. int field;        /* # of the dialog item to modify    */
  66. int width;        /* max # of digits in the field    */
  67. {
  68.     int itemtype;
  69.     ControlHandle item;
  70.     Rect itembox;
  71.     static char buf[100];
  72.     char *src, *dst;    /* pointers for removing non-digits    */
  73.  
  74.     GetDItem(ptr, field, &itemtype, &item, &itembox);
  75.     GetIText(item, buf);
  76.     ptoc(buf);
  77.     
  78.     dst = &buf[0];
  79.     for (src = &buf[0]; (*dst = *src); ++src) {
  80.         if (*dst >= 0 && *dst <= '9') ++dst;
  81.     }
  82.     buf[width] = '\0';
  83.  
  84.     ctop(buf);
  85.     SetIText(item, buf);
  86. }
  87.